package com.hand.demo.app.service.impl;

import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.hand.demo.app.service.HhrTaEducationService;
import org.springframework.stereotype.Service;
import com.hand.demo.domain.entity.HhrTaEducation;
import com.hand.demo.domain.repository.HhrTaEducationRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 标准化教育经历表(HhrTaEducation)应用服务
 *
 * @author
 * @since 2025-06-16 12:16:54
 */
@Service
public class HhrTaEducationServiceImpl implements HhrTaEducationService {
    @Autowired
    private HhrTaEducationRepository hhrTaEducationRepository;

    @Override
    public Page<HhrTaEducation> selectList(PageRequest pageRequest, HhrTaEducation hhrTaEducation) {
        return PageHelper.doPageAndSort(pageRequest, () -> hhrTaEducationRepository.selectList(hhrTaEducation));
    }

    @Override
    public void saveData(List<HhrTaEducation> hhrTaEducations) {
        List<HhrTaEducation> insertList = hhrTaEducations.stream().filter(line -> line.getId() == null).collect(Collectors.toList());
        List<HhrTaEducation> updateList = hhrTaEducations.stream().filter(line -> line.getId() != null).collect(Collectors.toList());
        hhrTaEducationRepository.batchInsertSelective(insertList);
        hhrTaEducationRepository.batchUpdateByPrimaryKeySelective(updateList);
    }

    @Override
    public void deleteByResumeId(Long resumeId) {
        // 创建查询条件
        HhrTaEducation query = new HhrTaEducation();
        query.setResumeId(resumeId);
        List<HhrTaEducation> existingList = hhrTaEducationRepository.selectList(query);
        if (!existingList.isEmpty()) {
            hhrTaEducationRepository.batchDeleteByPrimaryKey(existingList);
        }
    }
}

